Skip to content

Test the export lease, cleanup, download, and archive steps - #168

Merged
PDowney merged 2 commits into
mainfrom
pipeline-tests
Nov 26, 2026
Merged

PDowney merged 2 commits into
mainfrom
pipeline-tests

Conversation

@PDowney

@PDowney PDowney commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Summary

The unit suite covered about 20% of the plugin's lines, mostly the admin page and helpers. The export pipeline itself (lease, cleanup, download, archive) had almost no tests. This adds them.

Test Covers File coverage after
LeaseTest lease validation, single-site and network repositories, acquisition under the lock, reclaiming expired and invalid rows, renewal, the directory update, release lease.php 287/299
CleanupTest scheduling, bulk and stale cleanup, scheduled deletion, recovery of an interrupted export, deactivation, uninstall cleanup.php 270/305
DownloadTest download and deletion request checks, the rate limit, path and identity validation, opening the exact file download.php 98/133
ArchiveTest database compression, the manifest, tar entries, the combined ZIP, and a full build that stops at the files step archive.php
ProcessHelperTest WP-CLI path checks, child environment, log output process.php (portable parts)

New test doubles:

  • tests/WpdbDouble.php: a wpdb backed by in-memory SQLite. The plugin's lease queries run unchanged; BINARY is dropped (SQLite already compares text byte by byte), and GET_LOCK()/RELEASE_LOCK() are SQLite functions whose results a test sets. It also provides add_option, add_network_option and the other functions that write through it.
  • WP_Filesystem_Direct: now implements the 14 methods the plugin uses, against the real disk. It reports back the modes it sets, so the plugin's private-permission checks behave on Windows as they do on Linux.
  • Other stand-ins: single cron events, wp_unschedule_hook, delete_option, delete_network_option, get_sites, site switching, wp_mkdir_p, wp_delete_file(_from_directory), and a wp_safe_redirect that throws, as wp_die already does.

Not covered here:

  • Streaming the download: it ends the PHP process and clears PHPUnit's output buffers.
  • Launching WP-CLI: it needs setsid and POSIX ownership checks, so Linux only. failOnSkipped would fail a local Windows run.
  • The files-archive walk: the suite fixes ABSPATH to a directory that doesn't exist.

MINIMUM_LINE_COVERAGE rises from 15 to 58, and the coverage job names pdo_sqlite.

Testing

  • PHPUnit: 318 tests pass. Line coverage is 62.98% (1,640 of 2,604), up from 20.4%. The new suite also passes on PHP 8.4.
  • composer check-all, npm test (21), yamllint, actionlint and gitleaks pass.

🤖 Generated with Claude Code

The export pipeline had almost no tests: the unit suite covered about
20% of the plugin's lines, mostly the admin page and helpers. New tests:

- LeaseTest: lease validation, the single-site and network repositories,
  acquisition under the lock, reclaiming expired and invalid rows,
  renewal, the directory update, and release.
- CleanupTest: scheduling, bulk and stale cleanup, scheduled deletion,
  recovery of an interrupted export, deactivation, and uninstall.
- DownloadTest: the download and deletion request checks, the rate
  limit, path and identity validation, and opening the exact file.
- ArchiveTest: database compression, the manifest, tar entries, the
  combined ZIP, and a full build that stops at the files step.
- ProcessHelperTest: the WP-CLI path checks, child environment, and log
  output.

The doubles they use: a wpdb backed by in-memory SQLite (tests/
WpdbDouble.php), so the lease queries run unchanged; a disk-backed
WP_Filesystem_Direct that reports the modes it sets, so permission
checks behave on Windows as on Linux; and cron, option, site, redirect,
and file-deletion stand-ins.

Line coverage rises from about 20% to 63%, so the CI floor rises from
15% to 58%; the coverage job names pdo_sqlite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for contributing to EngineScript Site Exporter!

Before we review:

  • Have you tested your changes with WordPress 7.0+?
  • Are your changes compatible with PHP 8.3+?
  • Have you followed WordPress coding standards?
  • Did you update the CHANGELOG.md if needed?

Security Reminder
This plugin creates site export archives, so please ensure:

  • All user input is properly sanitized
  • All output is properly escaped
  • No security vulnerabilities are introduced

We'll review your PR soon.

@codacy-production

codacy-production Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 211 complexity · 0 duplication

Metric Results
Complexity 211
Duplication 0

View in Codacy

🟢 Coverage ∅ diff coverage · +43.25% coverage variation

Metric Results
Coverage variation ✅ +43.25% coverage variation (-1.00%)
Diff coverage ✅ ∅ diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (7c2ecb2) 2612 534 20.44%
Head commit (b2e0f4f) 2611 (-1) 1663 (+1129) 63.69% (+43.25%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#168) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

…inks

GitHub's Ubuntu runner has a /var/www/html, the suite's ABSPATH, so the
full build completes there instead of stopping at the files step. The
test now checks that either outcome is clean: the staging directory is
always removed, and a completed build holds the three bundle entries.

Codacy's Opengrep flagged unlink() in the test doubles and fixtures; each
deletes a path the test created, so each gets a nosemgrep note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PDowney
PDowney merged commit b13bbb0 into main Nov 26, 2026
29 checks passed
@github-actions
github-actions Bot deleted the pipeline-tests branch November 26, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant